package com.lablzh.gdxy.repository.practice;

import com.lablzh.gdxy.entity.practice.StudentPractice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;

public interface StudentPracticeRepository extends JpaRepository<StudentPractice,Integer> {


    List<StudentPractice> findAllByStudentName(String studentName);

    List<StudentPractice> findAllByCollege(String category);

    List<StudentPractice> findAllByCollegeAndMajor(String category, String major);

    List<StudentPractice> findAllByCollegeAndMajorAndClasses(String category, String major, String classes);
    @Transactional
    void deleteByProjectIDAndStudentUsername(Integer projectID, String studentUsername);

    List<StudentPractice> findAllByStudentUsername(String username);

    List<StudentPractice> findAllByProjectID(Integer id);

    List<StudentPractice> findAllByProjectIDAndSummit(Integer id, String summit);

    List<StudentPractice> findAllByProjectIDAndReview(Integer id, String review);



    @Modifying
    @Transactional
    @Query("update StudentPractice set  reportScore=?3,reportLevel=?4,note=?5,review=?6 where projectID=?1 and studentUsername=?2")
    void updateReportScoreAndReportLevelAndNoteAndReviewByProjectIDAndStudentUsername(Integer id, String studentUsername, Integer score, String level, String note, String review);

    @Transactional
    void deleteByProjectID(Integer id);



    @Modifying
    @Transactional
    @Query("update StudentPractice set summit=?3 ,review=?4 where projectID=?1 and studentUsername=?2")
    void updateSummitAndReviewByIdAndStudentUsername(Integer id,String username, String summit,String review);

    @Modifying
    @Transactional
    @Query("update StudentPractice set  reportName=?3,summitTime=?4  where projectID=?1 and studentUsername=?2")
    void updateReportNameAndSummitTimeByIdAndStudentUsername(Integer id,String username ,String filename,LocalDate now);

    StudentPractice findAllByProjectIDAndStudentUsername(Integer id, String username);

    List<StudentPractice> findAllByStudentNameAndGrade(String studentName, String grade);

    List<StudentPractice> findAllByCollegeAndGrade(String college, String grade);

    List<StudentPractice> findAllByCollegeAndMajorAndGrade(String college, String major, String grade);

    List<StudentPractice> findAllByCollegeAndMajorAndClassesAndGrade(String college, String major, String classes, String grade);

}



